﻿
Partial Class WebForm_ManageWorkRecord_AddLeader
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.FormView_WorkHeader.InsertItemTemplate = Me.FormView_WorkHeader.ItemTemplate
        Me.FormView_WorkHeader.EditItemTemplate = Me.FormView_WorkHeader.ItemTemplate
    End Sub

    Protected Sub FormView_WorkHeader_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView_WorkHeader.DataBound

        If Me.FormView_WorkHeader.CurrentMode = FormViewMode.Edit Then
            Me.UOrganizationID = DataBinder.Eval(Me.FormView_WorkHeader.DataItem, "UOrganizationID").ToString()
            Me.VOrganizationID = DataBinder.Eval(Me.FormView_WorkHeader.DataItem, "VUOrganizationID").ToString()
            Me.VolunteerID = DataBinder.Eval(Me.FormView_WorkHeader.DataItem, "LeaderID").ToString()
            TryCast(Me.FormView_WorkHeader.FindControl("txtTakeDate"), WebForm_CommonControl_CalendarTextBox).Enabled = False
        ElseIf Me.FormView_WorkHeader.CurrentMode = FormViewMode.Insert Then
            '認養日期限制為今天功能取消 2012/02/13
            'TryCast(Me.FormView_WorkHeader.FindControl("txtTakeDate"), WebForm_CommonControl_CalendarTextBox).Enabled = False
            ''隱藏清潔內容
            'TryCast(Me.FormView_WorkHeader.FindControl("PanelA"), Panel).Visible = False
            'TryCast(Me.FormView_WorkHeader.FindControl("AddWorkItemControl1"), WebForm_AddControl_AddWorkItemControl).Visible = False
        End If
        'ScriptManager.GetCurrent(Me.Page).RegisterPostBackControl(TryCast(Me.FormView_WorkHeader.FindControl("btSelect"), Button))
        'TryCast(Me.FormView_WorkHeader.FindControl("chk_LeaderName"), RequiredFieldValidator).ValidationGroup = Me.ValidationGroup
    End Sub

    Protected Sub FormView_WorkHeader_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs)
        If e.CommandName = "GetData" Then
            'Me.UOrganizationID = HttpContext.Current.Request.Cookies("UOrganizationID").Value
            Me.SearchUOrganizationControl1.Show(Me.UOrganizationID)
        End If
    End Sub

    Protected Sub SearchUOrganizationControl1_SelectedIndexChanged(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchUOrganizationControl1.SelectedIndexChanged
        TryCast(Me.FormView_WorkHeader.FindControl("txtUOrganizationName"), TextBox).Text = Me.SearchUOrganizationControl1.OrganizationName
        TryCast(Me.FormView_WorkHeader.FindControl("txtVOrganizationName"), TextBox).Text = Me.SearchUOrganizationControl1.VOrganizationName
        TryCast(Me.FormView_WorkHeader.FindControl("txtLeaderName"), TextBox).Text = Me.SearchUOrganizationControl1.VolunteerName
        TryCast(Me.FormView_WorkHeader.FindControl("txtLeaderTel"), TextBox).Text = Me.SearchUOrganizationControl1.OfficePhone

        Me.UOrganizationID = Me.SearchUOrganizationControl1.UOrganizationID
        Me.VOrganizationID = Me.SearchUOrganizationControl1.VOrganizationID
        Me.VolunteerID = Me.SearchUOrganizationControl1.VolunteerID
    End Sub

    Public Sub InitData(ByVal intWorkHeaderID As Integer)

        WorkHeaderID = intWorkHeaderID

        If intWorkHeaderID = 0 Then
            '新增
            Me.DataAccessMode = FormViewMode.Insert
            Me.FormView_WorkHeader.ChangeMode(FormViewMode.Insert)
        Else
            '編輯
            Me.DataAccessMode = FormViewMode.Edit
            Me.FormView_WorkHeader.ChangeMode(FormViewMode.Edit)

        End If

        Me.BindFV()
    End Sub

    Public Sub BindFV()
        Dim wrManager As New WorkRecordManager
        Me.FormView_WorkHeader.datasource = wrManager.GetAddLeader(WorkHeaderID)
        Me.FormView_WorkHeader.DataBind()

    End Sub
    Public Property DataAccessMode() As FormViewMode
        Get
            Return ViewState("DataAccessMode")
        End Get
        Set(ByVal value As FormViewMode)
            ViewState("DataAccessMode") = value
        End Set
    End Property

    Public Property WorkHeaderID() As Integer
        Get
            Return ViewState("WorkHeaderID")
        End Get
        Set(ByVal value As Integer)
            ViewState("WorkHeaderID") = value
        End Set

    End Property

    Public Property UOrganizationID() As String
        Get
            Return ViewState("UOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("UOrganizationID") = value
        End Set

    End Property

    Public Property VOrganizationID() As String
        Get
            Return ViewState("VOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("VOrganizationID") = value
        End Set

    End Property

    Public Property VolunteerID() As String
        Get
            Return ViewState("VolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerID") = value
        End Set

    End Property

    Public Property ValidationGroup() As String
        Get
            Return ViewState("ValidationGroup")
        End Get
        Set(ByVal value As String)
            ViewState("ValidationGroup") = value
        End Set

    End Property

    Public ReadOnly Property TakeDate() As Date
        Get
            Return TryCast(Me.FormView_WorkHeader.FindControl("txtTakeDate"), WebForm_CommonControl_CalendarTextBox).Value
        End Get

    End Property
    Public ReadOnly Property LeaderName() As String
        Get
            Return TryCast(Me.FormView_WorkHeader.FindControl("txtLeaderName"), TextBox).Text.Trim()
        End Get
    End Property
    Public ReadOnly Property VOrgName() As String
        Get
            Return TryCast(Me.FormView_WorkHeader.FindControl("txtVOrganizationName"), TextBox).Text.Trim()
        End Get
    End Property
    Public ReadOnly Property Phone() As String
        Get
            Return TryCast(Me.FormView_WorkHeader.FindControl("txtLeaderTel"), TextBox).Text.Trim()
        End Get
    End Property
End Class
